﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pixysoft.Framework.Noebe
{
    public class ConnectionPoolSnapshot
    {
        private int connectionAvailableSize = -1;

        private int connectionRemovedQueueSize = -1;

        private long requestRemovedCount = -1;

        private long connectionRemovedCount = -1;

        private long totalRequestTime = -1;

        private DateTime connectionLastLazyTime = DateTime.MinValue;

        private int connectionNextConnectionId = -1;

        private List<ConnectionSnapshot> availableConnections = new List<ConnectionSnapshot>();

        private List<ConnectionSnapshot> removedConnections = new List<ConnectionSnapshot>();

        public int GetConnectionAvailableSize()
        {
            return connectionAvailableSize;
        }

        public void SetConnectionAvailableSize(int connectionAvailableSize)
        {
            this.connectionAvailableSize = connectionAvailableSize;
        }

        public int GetConnectionRemovedQueueSize()
        {
            return connectionRemovedQueueSize;
        }

        public void SetConnectionRemovedQueueSize(int connectionRemovedSize)
        {
            this.connectionRemovedQueueSize = connectionRemovedSize;
        }

        public DateTime GetConnectionLastLazyTime()
        {
            return connectionLastLazyTime;
        }

        public void SetConnectionLastLazyTime(DateTime connectionLastLazyTime)
        {
            this.connectionLastLazyTime = connectionLastLazyTime;
        }

        public int GetConnectionNextConnectionId()
        {
            return connectionNextConnectionId;
        }

        public void SetConnectionNextConnectionId(int connectionNextConnectionId)
        {
            this.connectionNextConnectionId = connectionNextConnectionId;
        }

        public List<ConnectionSnapshot> GetAvailableConnections()
        {
            return availableConnections;
        }

        public List<ConnectionSnapshot> GetRemovedConnections()
        {
            return removedConnections;
        }

        public long GetTotalRequestTime()
        {
            return totalRequestTime;
        }

        public void SetTotalRequestTime(long totalRequestTime)
        {
            this.totalRequestTime = totalRequestTime;
        }

        public long GetRequestRemovedCount()
        {
            return requestRemovedCount;
        }

        public void SetRequestRemovedCount(long requestRemovedCount)
        {
            this.requestRemovedCount = requestRemovedCount;
        }

        public long GetConnectionRemovedCount()
        {
            return connectionRemovedCount;
        }

        public void SetConnectionRemovedCount(long connectionRemovedCount)
        {
            this.connectionRemovedCount = connectionRemovedCount;
        }


        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Transaction Pool:");
            builder.AppendLine("-------------------------------");
            builder.AppendLine("nextId:" + this.GetConnectionNextConnectionId() + ";");
            builder.AppendLine("lazyTime:" + this.GetConnectionLastLazyTime() + ";");
            builder.AppendLine("AvailableSize:" + this.GetConnectionAvailableSize() + ";");
            builder.AppendLine("RemovedSize:" + this.GetConnectionRemovedQueueSize() + ";");
            builder.AppendLine("TotalRequest:" + this.GetTotalRequestTime() + ";");
            builder.AppendLine("TotalRemovedConnection:" + this.GetConnectionRemovedCount() + ";");
            builder.AppendLine("TotalRemovedRequest:" + this.GetRequestRemovedCount() + ";");
            builder.AppendLine("");

            foreach (ConnectionSnapshot conn in this.GetAvailableConnections())
            {
                builder.Append(">>AVAILABLE:").Append("id\t" + conn.ConnectionId).Append("\tdate\t" + conn.CreateDate).Append(
                        "\ttimes\t" + conn.RequestTimes).Append("\tcount\t" + conn.RequestCount).AppendLine("");
            }
            foreach (ConnectionSnapshot conn in this.GetRemovedConnections())
            {
                builder.Append(">>REMOVED:").Append("id\t" + conn.ConnectionId).Append("\tdate\t" + conn.CreateDate).Append(
                        "\ttimes\t" + conn.RequestTimes).Append("\tcount\t" + conn.RequestCount).AppendLine("");
            }

            return builder.ToString();
        }
    }

}
